define(function (require,exports,module) {
	var angular = require('angular');
	var app = angular.module('channel.services',[]);
	
    var api_prefix = G_CONFIG["api_prefix"] + "qmyx/third-party"; //api前缀
    
	app
    .factory('url', [
            function () {
                return {
                    //给url添加search字符串
                    addParam: function (url, search) {
                        for (var key in search) {
                            if (search.hasOwnProperty(key) && search[key]) {
                                var connecter = "&";
                                if (url.indexOf('?') === -1) {
                                    connecter = "?";
                                }
                                url += connecter + key + '=' + encodeURIComponent(search[key]);
                            }
                        }
                        return url;
                    }
                };
            }
        ])
        .factory('channelService',[
		'$http',
        'url',
		function ($http,url) {
			return {
				getUserList: function (options) {
                     var api = url.addParam(api_prefix + '/get-user-list',options.search);
					 return $http.get(api,{
                        	NEED_TOKEN:false
                    	})
                        .success(function(res){
                            if (res && res.retCode == 0) {                               
                                options.success(res);
                                return;
                            }
                            options.fail && options.fail(res);
                        })
                        .error(function(res) {
                            options.fail && options.fail(res);
                        })
				},
                getStatisticData: function(options){
                    var api = url.addParam(api_prefix + '/statistics-data',options.search);
                    return $http.get(api,{
                        	NEED_TOKEN:false
                    	})
                        .success(function(res){
                            if (res && res.retCode == 0) {                               
                                options.success(res);
                                return;
                            }
                            options.fail && options.fail(res);
                        })
                        .error(function(res) {
                            options.fail && options.fail(res);
                        })
                },
                getChannelList: function(options){
                    var api = url.addParam(api_prefix + '/get-third-party',options.search);
                    return $http.get(api,{
                        	NEED_TOKEN:false
                    	})
                        .success(function(res){
                            if (res && res.retCode == 0) {                               
                                options.success(res);
                                return;
                            }
                            options.fail && options.fail(res);
                        })
                        .error(function(res) {
                            options.fail && options.fail(res);
                        });
                    
                },
                getSettingData: function (options){
                    var api = url.addParam(api_prefix + '/get-setting-data',options.search);
                    return $http.get(api,{
                        	NEED_TOKEN:false
                    	})
                        .success(function(res){
                            if (res && res.retCode == 0) {                               
                                options.success(res);
                                return;
                            }
                            options.fail && options.fail(res);
                        })
                        .error(function(res) {
                            options.fail && options.fail(res);
                        })
                },
                saveSettings: function (options){
                    var api = url.addParam(api_prefix + '/save-third-party-info',options.search);
                    return $http.post(api,options.data,{
                        	NEED_TOKEN:false
                    	})
                        .success(function(res){
                            if (res && res.retCode == 0) {                               
                                options.success(res);
                                return;
                            }
                            options.fail && options.fail(res);
                        })
                        .error(function(res) {
                            options.fail && options.fail(res);
                        })
                },
                getProjectList: function (options){
                    var api = url.addParam(G_CONFIG["api_prefix"] +'qmyx/customer-manage/get-project-list',options.search);
                    return $http.get(api,{
                        	NEED_TOKEN:false
                    	})
                        .success(function(res){
                            if (res && res.retCode == 0) {                               
                                options.success(res);
                                return;
                            }
                            options.fail && options.fail(res);
                        })
                        .error(function(res) {
                            options.fail && options.fail(res);
                        })
                },
                getAPIDocUrl: function(options){
                    return url.addParam(api_prefix +'/download-development-document',options.search);
                }
                
			}	
		}
	]);
	
});